home *** CD-ROM | disk | FTP | other *** search
/ HyperLib 1997 Winter - Disc 1 / HYPERLIB-1997-Winter-CD1.ISO.7z / HYPERLIB-1997-Winter-CD1.ISO / オンラインウェア / PRG / Menu Events 1.3.sit / Menu Events 1.3 / Menu Events Help (text) < prev    next >
Text File  |  1996-03-07  |  43KB  |  978 lines

  1. Menu Events 1.3
  2.  
  3. March 6, 1996
  4.  
  5.  
  6.  
  7. Disclaimer and Copyright Notice
  8.  
  9.  
  10. Menu Events is a free utility which lets you control another applicationユs
  11. menu commands by sending it an Apple event.  The author, Ross Brown,
  12. makes no warranty, either express or implied, with respect to this
  13. software, its performance, merchantability, or suitability for any
  14. particular purpose.  People using the Menu Events utility do so at their
  15. own risk.  The author disclaims all liability for loss of data, mechanical
  16. damage, or other losses suffered while using the Menu Events utility.
  17.  
  18. Menu Events is an AWOL Software Production, Copyright ゥ 1994-6 Ross
  19. Brown.  All rights reserved.  Permission is granted to make and distribute
  20. copies of this software, provided this disclaimer and copyright notice are
  21. preserved on all copies.  The software may not, however, be sold or
  22. distributed for profit, or included with other software which is sold or
  23. distributed for profit, without the permission of the author.
  24.  
  25. There are no site license fees for the use of Menu Events within an
  26. organization.  The author encourages you to make and distribute as many
  27. copies of the system extension as you wish, for whomever you wish, as
  28. long as it is not for profit.  Menu Events is part of a set of cooperating
  29. programs, AWOL Utilities.  The tutorial help you are reading is designed
  30. for handling by the help server application Help on Wheels, which is also
  31. part of AWOL Utilities.
  32.  
  33.  
  34.  
  35. Distribution Policy
  36.  
  37.  
  38. New versions of individual AWOL Utilities programs, including Menu
  39. Events, are available by anonymous FTP from popular archive sites
  40. including sumex-aim.stanford.edu, mac.archive.umich.edu, and their
  41. respective mirror sites, and through Usenet news group
  42. comp.binaries.mac.
  43.  
  44. Support for AWOL Utilities is through Internet mail at address
  45. ab026@freenet.carleton.ca.  The software is not available by FTP from
  46. this site.  The address for paper correspondence is AWOL Software
  47. Productions, PO Box 24207, 300 Eagleson Road, Kanata, Ontario, Canada
  48. K2M 2C3.
  49.  
  50. Macintosh users who do not have access to electronic sources of free and
  51. shareware software may obtain a copy of AWOL Utilities by sending a
  52. self-addressed stamped envelope and an 800K (or larger) formatted
  53. diskette to the author at the above address.  U.S. users are reminded that
  54. postage from Canada in 1996 is C$0.52 up to 30 grams (1 oz.), C$0.77 up
  55. to 50 grams (1 3/4 oz.), and C$1.17 up to 100 grams (3 1/2 oz.).
  56. US$0.50, US$0.75, and US$1.00 in coin is acceptable in place of stamps
  57. for the respective weights.  People outside the U.S. and Canada may send
  58. an international postal reply coupon instead of Canadian stamps (available
  59. from any post office).  Please use sturdy envelopes, preferably cardboard
  60. disk mailers.  (Mailers over 5 mm (1/5") thick require C$1.17 postage to
  61. the U.S.)
  62. Please do not send return envelopes with non-Canadian
  63. stamps, as Canada Post will not accept them.
  64.  
  65.  
  66.  
  67. About AWOL Software Productions
  68.  
  69.  
  70. AWOL Software Productions specializes in custom development of
  71. software for the Mac OS.  Since its inception in 1990, AWOL has
  72. developed a number of programs which enhance the Mac OS user
  73. experience, working in nearly every part of the Macintosh Toolbox.  If
  74. you have a short-term programming task or product idea but lack the
  75. staff to do the expert design, coding, and documentation, we invite your
  76. inquiry.
  77.  
  78. Virtual Desktop is AWOLユs best-known effort, serving the desktop
  79. expansion needs of thousands of Mac users around the world.  Later in
  80. 1996, AWOL will release a new commercial version 2.0 to replace the
  81. freeware version contained in the AWOL Utilities package.  Please contact
  82. us at ab026@freenet.carleton.ca for feature and ordering information.
  83.  
  84. Users who want more out of the Macユs speech capabilities should check
  85. out MacYack Pro, a jointly developed package of speech tools marketed by
  86. Scantron Quality Computers (qualitycomp@aol.com; 20200 Nine Mile Rd.,
  87. St. Clair Shores, MI 48080).
  88.  
  89.  
  90.  
  91. Purpose
  92.  
  93.  
  94. The big trend these days in Macintosh software is toward more
  95. integration between applications.  Increasingly, developers achieve this
  96. integration by using the Apple event interfaces of other applications, and
  97. by defining their own suites of Apple events for other applications to use.
  98.  
  99. Because there are far more clients than servers in the world of Apple
  100. events, there is a large number of メhigh-level-event-awareモ applications
  101. which support program linking, using Apple events to control other
  102. applications (or just to be modern), but not offering any interface of their
  103. own.  Apart from the Required suite mandated by Finder, the functionality
  104. of these applications is beyond the reach of scripting utilities and other
  105. programs that send Apple events.  Menu Events is a utility which opens up
  106. this demi-monde of dabblers and dilettantes to the glories of Apple event
  107. controllability.  Applications which are by their nature only
  108. high-level-event-aware become scriptable and recordable Apple event
  109. servers.
  110.  
  111. If you regard an applicationユs collective user interface in terms of a set
  112. of available functions, then take subsets according to how the user can
  113. access these functions (Command-key combination, button click, menus,
  114. and so on), you will usually find that the subset for menus is largest.  This
  115. is because menus are intended as a baseline for the user interface;
  116. however else you can do something, you should be able to do it with menus
  117. as well.  Often a function is not available in a certain mode, but a menu
  118. selection will shift the application into that mode, then another will access
  119. the function.  This conformity is an asset of the Macintosh operating
  120. system which can be exploited to offer a fairly general means of
  121. controlling other applications.
  122.  
  123.  
  124.  
  125. Who Can Use Menu Events?
  126.  
  127.  
  128. You do not need AppleScript, or any other optional software package, for
  129. Menu Events to work.  It only requires System 7.
  130.  
  131. However, it has no user interface of its own.  It only enables programs to
  132. do something they would not otherwise be able to do, namely, invoke
  133. another applicationユs menu commands.
  134.  
  135. Any program you write, or any application which lets you compose and
  136. send Apple events (such as a general scripting utility, or Maybe, part of
  137. AWOL Utilities), can send a Menu event to any suitably modern application
  138. and hope for a response.  Whether or not a particular application
  139. cooperates depends on how it was programmed, but any application
  140. programmed according to the published instructions of Apple Computer
  141. will cooperate, with a bit of coaxing.
  142. See the section entitled メLimitationsモ for more information.
  143.  
  144. Menu events can be received from any machine on the AppleTalk network,
  145. subject to the usual Users & Groups program linking permission scheme.
  146. This allows you to use Menu events to control applications from a remote
  147. location.
  148.  
  149. If you have AppleScript, you should place the メMenu Events Scripting
  150. Additionモ file in your メScripting Additionsモ folder.  This will allow you
  151. to use Menu events in your scripts.  (Unlike most scripting additions, this
  152. one only describes event terminology, and does not implement the event
  153. handlers themselves, so it is useless without the Menu Events extension.)
  154. メMenu Events Sample Scriptモ shows the sort of thing you can do with the
  155. scripting addition file installed.  Before writing a script to control a
  156. target application, you should try recording its menu actions using your
  157. script editor.  If the target application supports program linking, and the
  158. Caps Lock key is down, these actions will be recorded as Menu Events
  159. script commands.
  160.  
  161.  
  162.  
  163. What Does Menu Events Do?
  164.  
  165.  
  166. Menu Events is a system extension.  Once you have placed it in your
  167. Extensions folder and restarted your Macintosh, it adds a small suite of
  168. Apple events (メMenu eventsモ) to the set supported by every
  169. high-level-event-aware application.  Also, if the Caps Lock key is down,
  170. it alters menu selection logic so that the selection is recorded as a Menu
  171. event.  This capability allows a script editor to record menu actions as
  172. script commands.
  173.  
  174. Many people are justly wary of control panels and system extensions,
  175. because of the conflicts they often cause with System software and with
  176. each other.  These conflicts usually result from competitive trap patching.
  177.  
  178. Menu Events installs a GetNextEvent filter and patches the MenuSelect
  179. trap at system startup to enable the Apple event recording capability, and
  180. installs an Apple event handler in the system dispatch table.  The Apple
  181. event handler cannot conflict with any other, because it is bound
  182. specifically to the Menu event class.  Menu Events does patch some traps
  183. メon the flyモ to simulate menu selection, but the patches remove
  184. themselves immediately.
  185.  
  186. There are three events defined in the suite, and they work as follows.
  187. See the section entitled メMenu Events Suiteモ for more information on the
  188. Menu Events suite.
  189.  
  190.  
  191. Query Menu List Event
  192.  
  193. This event, with no parameters, queries the menu list of the target
  194. application.  If the application is high-level-event-aware, not
  195. background-only, and has a menu bar, it will return a list of records, each
  196. containing a menu ID (integer), a title (string), an enable/disable
  197. (Boolean), and a menu definition procedure resource ID (integer)
  198. parameter.  If you do not know the IDs or titles of the target applicationユs
  199. menus, this is one way to find out.  (Another way is to press the Caps
  200. Lock key and record menu actions using a script editor; yet another is to
  201. use the Menu Grabber application, also part of AWOL Utilities.)  Be aware
  202. that menu IDs do not have to agree with 'MENU' resource IDs, though they
  203. often do.
  204. See the section entitled メSuggestions for Useモ for more information on
  205. Menu Grabber.
  206.  
  207. System menus (Keyboard, Help, Application), hierarchical menus, and
  208. pop-up menus do not appear in this list, but the Apple menu does.
  209.  
  210. NOTE:  The standard menu definition procedure ('MDEF') resource ID is 0.
  211. A value of -1 indicates that the menu definition procedure is not a
  212. resource.  Non-standard menu definition procedures may have abnormal
  213. ways of counting, disabling, and displaying menu items, so be careful with
  214. them.
  215.  
  216.  
  217. Query Menu Event
  218.  
  219. This event, given a menu ID (integer) and/or menu title (string)
  220. parameter, queries the items of a certain target application menu.  If the
  221. application has a menu with that ID and/or title, be it a regular, system,
  222. hierarchical, or pop-up menu, it will return a list of records, one per
  223. menu item, each containing a menu item ID (integer), an item text
  224. (string), an enable/disable (Boolean), a mark character (integer), an icon
  225. ID (integer), a style value (integer), and a Command character (integer)
  226. parameter.  The items are numbered starting from 1 at the top end of the
  227. menu.  Separators appear as disabled items with an item text of メ-モ.
  228.  
  229. This event simulates a simple click in the applicationユs menu bar, to force
  230. it to bring its menus up to date.
  231.  
  232. You may optionally include Boolean parameters to indicate which modifier
  233. keys (Shift, Control, Option, Command) are pressed at the time of the
  234. simulated menu bar click, in case this makes a difference in the content of
  235. the menu.
  236.  
  237. This event does work for menus which use a non-standard menu definition
  238. procedure ('MDEF'), but the results may or may not reflect what you see
  239. when you pull down the menu, depending on how the procedure was
  240. programmed.
  241.  
  242. This event brings the target application to the front before forcing the
  243. menu bar click upon it.  If the sender was on the same machine, and was
  244. previously in front, it returns to the front after the menu query is
  245. complete.
  246. See the section entitled メHow Does Menu Events Work?モ for more
  247. information about the method by which Menu Events activates the target
  248. application.
  249.  
  250.  
  251. Select Menu Item Event
  252.  
  253. This event, given a menu ID (integer) and/or menu title (string)
  254. parameter and a menu item ID (integer) and/or menu item text (string)
  255. parameter, asks the application to act as though the user pulled down that
  256. menu and selected that item.  This does not work for the Keyboard and
  257. Application menus, which are not under the control of the application, nor
  258. for the upper (System-defined) part of the Help menu, but it works for
  259. any regular, application-defined, enabled menu item.
  260.  
  261. If you use the menu item text parameter to specify the menu item to
  262. select, be sure to match any special characters in the text, especially the
  263. ellipsis ('ノ') character which often appears at the end of the string,
  264. which is not the same as three period characters, despite its appearance.
  265.  
  266. You may optionally include Boolean parameters to indicate which modifier
  267. keys (Shift, Control, Option, Command) are pressed at the time of the
  268. simulated menu item selection, in case this makes a difference in the
  269. effect of the selection.
  270.  
  271. This event does work for menus which use a non-standard menu definition
  272. procedure ('MDEF'), but the results may or may not reflect what happens
  273. when you select from the menu, depending on how the procedure was
  274. programmed.
  275.  
  276. This event brings the target application to the front before forcing the
  277. menu selection upon it.  If the sender was on the same machine, and was
  278. previously in front, it returns to the front after the menu action is
  279. complete.
  280. See the section entitled メHow Does Menu Events Work?モ for more
  281. information about the method by which Menu Events activates the target
  282. application.
  283.  
  284.  
  285.  
  286. How Does Menu Events Work?
  287.  
  288.  
  289. When you send a Query Menu List event, the ideal application dispatches
  290. the resulting high-level event as an Apple event without looking at it.  The
  291. event handler provided by Menu Events forms a reply to the query on the
  292. basis of the applicationユs menu list structure.  Through all of this, the
  293. application stays in the background or in the foreground, wherever it was
  294. before.
  295.  
  296. When you send a Query Menu or Select Menu Item event, the same things
  297. happen, but the event handling is more complex.
  298.  
  299. First, it verifies that the given menu is valid.  If not, it returns
  300. noSuchMenuErr.
  301.  
  302. Second, it asks for the application to be brought to the front for user
  303. interaction, because it could be dangerous to feed the target application a
  304. menu bar click while it is in the background, something that never happens
  305. in normal operation.  If it is refused, it returns errAENoUserInteraction.
  306.  
  307. Third, it patches some traps so that it can gain control of menu bar clicks.
  308. If it finds that the patches are already in place, meaning that an earlier
  309. Menu event is still pending, it returns menuEventPendingErr.
  310.  
  311. Fourth, if everything is OK, it posts an event to simulate a mouse click in
  312. the menu bar, with modifier keys if specified.  The patched traps tell the
  313. application that no menu item was selected.  The patches then remove
  314. themselves.  This step is solely to ensure that the application brings its
  315. menus up to date.
  316.  
  317. Fifth (in the case of a Select Menu Item event), it verifies that the given
  318. menu item is valid and enabled.  If not, it returns noSuchMenuErr,
  319. noSuchMenuItemErr, or menuItemDisabledErr.  If the menu has a
  320. non-standard menu definition procedure, its way of counting or disabling
  321. items may differ from the norm.  Menu Events assumes that the count and
  322. enable/disable flags are set in the normal fashion.
  323.  
  324. Sixth (in the case of a Select Menu Item event), it posts an event to
  325. simulate another mouse click in the menu bar, with modifier keys if
  326. specified.  The patched traps tell the application that the given item was
  327. selected.  The patches then remove themselves.  From there, it is exactly
  328. as though the user had actually made the selection.
  329.  
  330. NOTE:  When replying to any of the three event types, Menu Events
  331. includes a null メtattooモ parameter to prove that it handled the event,
  332. rather than some handler supplied by the application.  Many Microsoft
  333. applications, for example, bind their own handler over all Apple event
  334. classes, preventing Menu Events from working.  (The handler wouldnユt be
  335. a problem if it returned errAEEventNotHandled when faced with an
  336. unknown Apple event, as it should.)
  337.  
  338.  
  339. User Interaction Policy
  340.  
  341. The Apple Event Manager implements a complicated but sensible model for
  342. joint sender/receiver control over user interaction.  Menu Events doesnユt
  343. know which menu selections will really require user interaction, but even
  344. if it did, it would still have to request user interaction just to bring the
  345. target application to the front, where an application always expects to be
  346. when it sees a mouse-down event.
  347.  
  348. The sending program must set the kAECanInteract or kAEAlwaysInteract
  349. flag in the sendMode parameter to AESend, in order to achieve user
  350. interaction.  It should also set the kAECanSwitchLayer flag, allowing the
  351. target application to come to the front without having to post a
  352. notification request.  If the target application is in the background, and
  353. receives a Menu event with this flag not set, it may go into a notification
  354. wait state, disrupting its usual background event processing behavior.
  355.  
  356. If both the sending program and target application are in the background,
  357. the kAECanSwitchLayer flag has no effect, and the notification request is
  358. posted anyway.  Since your sending program is indirectly instigating a
  359. user interaction, it should call AEInteractWithUser before sending the
  360. Menu event, if there is any chance that it will be in the background at the
  361. time.  Another approach would be to call SetFrontProcess to activate the
  362. target application before sending it a Menu event.
  363.  
  364. If the target application is in that rare user interaction state,
  365. kAEInteractWithSelf, where it disallows interaction requested by any
  366. other process, the Menu event handler will respect that state, and refuse
  367. the event.
  368.  
  369. If the sending and receiving applications are on different machines, the
  370. usual program linking checks apply, namely, Sharing Setup (on/off),
  371. Users & Groups (permission to user), and Finderユs Sharing (permission to
  372. application).
  373.  
  374. If the Menu Events extension is locked, using Finderユs Get Info dialog, then
  375. only target applications which explicitly allow interaction with all
  376. processes can be controlled by remote senders.  If it is not locked, and if
  377. it sees that the user interaction state is kAEInteractWithLocal, which is
  378. the default value, it will momentarily change it to kAEInteractWithAll, so
  379. that events sent from a remote machine are not rejected.  This trick is
  380. necessary for Menu Events to be useful with most target applications,
  381. because most will assume the default interaction state, not expecting any
  382. remote sender to require user interaction.  The icon displayed by Menu
  383. Events at startup shows whether or not the lock is in effect.
  384.  
  385. IMPORTANT NOTE:  Users of machines where Menu Events is installed
  386. should be careful about which users and applications are enabled for
  387. remote program linking.  In particular, guest users should not be allowed
  388. to do program linking unless Menu Events is locked.
  389.  
  390.  
  391. Apple Event Recording Capability
  392.  
  393. When you are using a high-level-event-aware application on a machine
  394. where Menu Events is installed, menu item selection behavior is modified
  395. if the Caps Lock key is down at the time you release the mouse button.
  396. Menu Events will create a Select Menu Item Apple event to represent the
  397. selection (including parameters for any modifier keys which were
  398. pressed), so that a script editor can record the event as a script
  399. command.  A gentle メtwangモ sound confirms that this has happened.
  400. Whether or not it succeeds in recording the event, the menu selection will
  401. be processed in the usual way.
  402.  
  403. If the application is scriptable in its own right, a script editor may record
  404. two commands when you select an item from its menus.  To prevent this
  405. duplication, you can use the itemユs Command-key equivalent (if any), or
  406. release the Caps Lock key, to suppress the recording capability.
  407.  
  408. If an application seems to be misinterpreting or not receiving menu
  409. selections, try again with the Caps Lock key up.  The command will not be
  410. recorded, but should work as usual.
  411.  
  412. NOTE:  While receiving a Select Menu Item event does simulate a menu
  413. selection, it does not cause a Select Menu Item script command to be
  414. recorded.
  415.  
  416.  
  417.  
  418. Suggestions for Use
  419.  
  420.  
  421. Menu Events is distributed as part of a free set of cooperating programs,
  422. AWOL Utilities.  This section explains how Menu Events can work in
  423. conjunction with the other programs.
  424.  
  425.  
  426. Help on Wheels
  427.  
  428. Help on Wheels is an efficient and full-featured help server which displays
  429. help files on behalf of client applications.  The help file you are reading is
  430. distributed alongside the Menu Events extension file as a separate Help on
  431. Wheels document.
  432.  
  433. Because Menu Events is not an application, its help support is limited.  To
  434. read this help, press the Help or Command-? key while the machine is
  435. starting up, and release the key once you see the Menu Events icon with a
  436. help balloon on it.  The help server will open to display the help file after
  437. startup is complete.
  438.  
  439.  
  440. Maybe
  441.  
  442. Maybe, the Finder alias enhancer, has an option allowing you to script a
  443. single Apple event and choose its target.  This Apple event will be sent
  444. just before the alias target is opened or printed.  In this way, you can
  445. achieve the effect of sending a simple Menu event by opening the
  446. converted alias.
  447.  
  448. Maybe does not require AppleScript or any other scripting system to send
  449. a Menu event.  Many programs, including all kinds of scripting utilities,
  450. offer a similar opportunity to send Menu events to any target application
  451. you choose.
  452.  
  453.  
  454. Menu Grabber
  455.  
  456. AWOL Utilities also contains an application, Menu Grabber, which uses
  457. Menu events to swap any target applicationユs menu bar over its own.
  458. This allows you to command most of the applicationユs functions from a
  459. remote location, although you will not see anything but the menus.  For
  460. most target applications, Menu Grabber will only be able to select menu
  461. items from a remote machine if the targetユs copy of Menu Events was
  462. unlocked at startup.
  463. See the section entitled メUser Interaction Policyモ for more information
  464. about the effect of locking the Menu Events extension.
  465.  
  466. When Menu Grabber grabs a menu, it adds a disabled item to show the
  467. menu ID.  This may help you if you are writing a program or script to send
  468. a Menu event to the application.
  469.  
  470.  
  471.  
  472. Menu Events Suite
  473.  
  474.  
  475. The following is a formal description of the Menu Events suite, in the form
  476. used in the Apple Event Registry.
  477.  
  478. NOTE:  The C header file メMenu Events.hモハcontains the constant
  479. definitions which appear here.  The メMenu Events Scripting Additionモ file
  480. contains an 'aete' resource which records the following dictionary
  481. information, for the benefit of scripting packages such as AppleScript.
  482. This package also includes a sample script, メMenu Events Sample
  483. Script,モ which demonstrates the usage of the following events and
  484. parameters.
  485.  
  486.  
  487. Apple events defined in the Menu Events suite
  488.  
  489. Name              Requested action
  490.  
  491. Query Menu List   List all application-defined menus
  492. Query Menu        List all items in a menu
  493. Select Menu Item  Perform a menu command
  494.  
  495.  
  496. Query Menu List - list all application-defined menus
  497.  
  498. A Query Menu List Apple event asks the application to return a list of
  499. records containing information about all menus defined by the application
  500. in its menu bar.  This information includes the Apple menu, but not the
  501. Help, Keyboard, or Application menus.
  502.  
  503. Event Class       kMEEventClass
  504.  
  505. Event ID          kAEMEQueryMenuList
  506.  
  507. Parameters        none
  508.  
  509. Reply Parameters
  510.  
  511. keyDirectObject
  512.                   Description:  A list of Apple event
  513.                                 records, one for each
  514.                                 menu, each containing the
  515.                                 following parameters
  516.                   Descriptor Type:  typeAEList
  517.                   Required or Optional?  Required
  518.  
  519.    keyMenuID
  520.                   Description:  The ID of the menu, not
  521.                                 necessarily equal to the
  522.                                 ID of the 'MENU' resource
  523.                                 it may have come from
  524.                   Descriptor Type:  typeShortInteger
  525.                   Required or Optional?  Required
  526.    keyMenuTitle
  527.                   Description:  The title of the menu, as
  528.                                 it appears in the menu bar
  529.                   Descriptor Type:  typeChar
  530.                   Required or Optional?  Required
  531.    keyMenuEnabled
  532.                   Description:  Whether or not the menu, as
  533.                                 a whole, is enabled
  534.                   Descriptor Type:  typeBoolean
  535.                   Required or Optional?  Required
  536.    keyMenuMDEFID
  537.                   Description:  The ID of the menu definition
  538.                                 procedure ('MDEF') resource,
  539.                                 ordinarily 0; -1 signifies
  540.                                 that the definition procedure
  541.                                 is not a resource
  542.                   Descriptor Type:  typeShortInteger
  543.                   Required or Optional?  Required
  544.  
  545. keyMenuEventsTattoo
  546.                   Description:  A null parameter to verify
  547.                                 that Menu Events handled
  548.                                 the event
  549.                   Descriptor Type:  typeNull
  550.                   Required or Optional?  Required
  551.  
  552. Result Codes
  553.                   mBarNFnd        -126    The application has
  554.                                           no menu bar
  555.  
  556.  
  557. Query Menu - list all items in a menu
  558.  
  559. A Query Menu Apple event asks the application to return a list of records
  560. containing information about all items in a given menu (selected by ID
  561. and/or title).  It requests user interaction to bring the application to the
  562. front, then posts mouse events to simulate a click in the menu bar, with
  563. modifier key states as specified, to force the application to update its
  564. menus, then reads the items from the given menu.  This information is
  565. complete enough to reconstruct the menu, except for the icon resources
  566. referenced by the keyMenuItemIcon parameter.
  567.  
  568. Event Class       kMEEventClass
  569.  
  570. Event ID          kAEMEQueryMenu
  571.  
  572. Parameters
  573.  
  574. keyMenuID
  575.                   Description:  The ID of the menu, as
  576.                                 returned by a Query Menu
  577.                                 List Apple event
  578.                   Descriptor Type:  typeShortInteger
  579.                   Required or Optional?  Optional
  580. keyMenuTitle
  581.                   Description:  The title of the menu, as
  582.                                 returned by a Query Menu
  583.                                 List Apple event
  584.                   Descriptor Type:  typeChar
  585.                   Required or Optional?  Optional
  586. NOTE:  Either keyMenuID or keyMenuTitle, or both, must be specified.
  587. keyShiftKeyPressed
  588.                   Description:  Whether the Shift key is
  589.                                 pressed at the time of the
  590.                                 simulated menu bar click
  591.                   Descriptor Type:  typeBoolean
  592.                   Required or Optional?  Optional
  593.                   Default Value:  false
  594. keyControlKeyPressed
  595.                   Description:  Whether the Control key is
  596.                                 pressed at the time of the
  597.                                 simulated menu bar click
  598.                   Descriptor Type:  typeBoolean
  599.                   Required or Optional?  Optional
  600.                   Default Value:  false
  601. keyOptionKeyPressed
  602.                   Description:  Whether the Option key is
  603.                                 pressed at the time of the
  604.                                 simulated menu bar click
  605.                   Descriptor Type:  typeBoolean
  606.                   Required or Optional?  Optional
  607.                   Default Value:  false
  608. keyCommandKeyPressed
  609.                   Description:  Whether the Command key is
  610.                                 pressed at the time of the
  611.                                 simulated menu bar click
  612.                   Descriptor Type:  typeBoolean
  613.                   Required or Optional?  Optional
  614.                   Default Value:  false
  615.  
  616. Reply Parameters
  617.  
  618. keyDirectObject
  619.                   Description:  A list of Apple event
  620.                                 records, one for each
  621.                                 item, each containing the
  622.                                 following parameters
  623.                   Descriptor Type:  typeAEList
  624.                   Required or Optional?  Required
  625.  
  626.    keyMenuItemID
  627.                   Description:  The ID of the item, numbered
  628.                                 from 1 at the top of the menu
  629.                   Descriptor Type:  typeShortInteger
  630.                   Required or Optional?  Required
  631.    keyMenuItemText
  632.                   Description:  The text of the item, as
  633.                                 it appears in the menu
  634.                   Descriptor Type:  typeChar
  635.                   Required or Optional?  Required
  636.    keyMenuItemEnabled
  637.                   Description:  Whether or not the item is
  638.                                 enabled
  639.                   Descriptor Type:  typeBoolean
  640.                   Required or Optional?  Required
  641.    keyMenuItemMark
  642.                   Description:  The mark character of the
  643.                                 item, in the lower byte
  644.                   Descriptor Type:  typeShortInteger
  645.                   Required or Optional?  Required
  646.    keyMenuItemIcon
  647.                   Description:  The icon number of the item,
  648.                                 which is 256 less than the
  649.                                 resource ID of the 'ICON' or
  650.                                 'cicn' resource
  651.                   Descriptor Type:  typeShortInteger
  652.                   Required or Optional?  Required
  653.    keyMenuItemStyle
  654.                   Description:  The style value of the item,
  655.                                 in the lower byte
  656.                   Descriptor Type:  typeShortInteger
  657.                   Required or Optional?  Required
  658.    keyMenuItemCmd
  659.                   Description:  The Command-key equivalent
  660.                                 character of the item, in the
  661.                                 lower byte
  662.                   Descriptor Type:  typeShortInteger
  663.                   Required or Optional?  Required
  664.  
  665. keyMenuEventsTattoo
  666.                   Description:  A null parameter to verify
  667.                                 that Menu Events handled
  668.                                 the event
  669.                   Descriptor Type:  typeNull
  670.                   Required or Optional?  Required
  671.  
  672. Result Codes
  673.                   mBarNFnd        -126    The application has
  674.                                           no menu bar
  675.                   errAENoUserInteraction
  676.                                   -1713   The application is
  677.                                           refusing to interact
  678.                                           with other processes
  679.                                           or (if Menu Events
  680.                                           extension is locked)
  681.                                           with remote processes
  682.                   noSuchMenuErr   -15950  The application has
  683.                                           no such menu
  684.                   menuMismatchErr
  685.                                   -15955  The given menu ID
  686.                                           and menu title
  687.                                           do not match
  688.  
  689.  
  690. Select Menu Item - perform a menu command
  691.  
  692. A Select Menu Item event simulates the selection of a command (selected
  693. by item ID and/or item text) from a menu (selected by ID and/or title).  It
  694. requests user interaction to bring the application to the front, then posts
  695. mouse events to simulate the selection of the given menu item, with
  696. modifier key states as specified.  If the Menu event is correctly handled,
  697. and the application reacts to the mouse events in the usual way, the result
  698. is as if the user had actually selected that menu item.  Interaction will fail
  699. if the application refuses to interact with other processes
  700. (kAEInteractWithSelf mode), or, if the application is on another machine
  701. and the Menu Events extension has been locked, if it refuses to interact
  702. with remote processes (kAEInteractWithLocal mode).
  703.  
  704. Event Class       kMEEventClass
  705.  
  706. Event ID          kAEMESelectMenuItem
  707.  
  708. Parameters
  709.  
  710. keyMenuID
  711.                   Description:  The ID of the menu, as
  712.                                 returned by a Query Menu
  713.                                 List Apple event
  714.                   Descriptor Type:  typeShortInteger
  715.                   Required or Optional?  Required
  716. keyMenuTitle
  717.                   Description:  The title of the menu, as
  718.                                 returned by a Query Menu
  719.                                 List Apple event
  720.                   Descriptor Type:  typeChar
  721.                   Required or Optional?  Optional
  722. NOTE:  Either keyMenuID or keyMenuTitle, or both, must be specified.
  723. keyMenuItemID
  724.                   Description:  The ID of the item, numbered
  725.                                 from 1 at the top of the menu
  726.                   Descriptor Type:  typeShortInteger
  727.                   Required or Optional?  Optional
  728. keyMenuItemText
  729.                   Description:  The text of the item, as
  730.                                 it appears in the menu
  731.                   Descriptor Type:  typeChar
  732.                   Required or Optional?  Optional
  733. NOTE:  Either keyMenuItemID or keyMenuItemText, or both, must be
  734. specified.
  735. keyShiftKeyPressed
  736.                   Description:  Whether the Shift key is
  737.                                 pressed at the time of the
  738.                                 simulated menu selection
  739.                   Descriptor Type:  typeBoolean
  740.                   Required or Optional?  Optional
  741.                   Default Value:  false
  742. keyControlKeyPressed
  743.                   Description:  Whether the Control key is
  744.                                 pressed at the time of the
  745.                                 simulated menu selection
  746.                   Descriptor Type:  typeBoolean
  747.                   Required or Optional?  Optional
  748.                   Default Value:  false
  749. keyOptionKeyPressed
  750.                   Description:  Whether the Option key is
  751.                                 pressed at the time of the
  752.                                 simulated menu selection
  753.                   Descriptor Type:  typeBoolean
  754.                   Required or Optional?  Optional
  755.                   Default Value:  false
  756. keyCommandKeyPressed
  757.                   Description:  Whether the Command key is
  758.                                 pressed at the time of the
  759.                                 simulated menu selection
  760.                   Descriptor Type:  typeBoolean
  761.                   Required or Optional?  Optional
  762.                   Default Value:  false
  763.  
  764. Reply Parameters
  765.  
  766. keyMenuEventsTattoo
  767.                   Description:  A null parameter to verify
  768.                                 that Menu Events handled
  769.                                 the event
  770.                   Descriptor Type:  typeNull
  771.                   Required or Optional?  Required
  772.  
  773. Result Codes
  774.                   mBarNFnd        -126    The application has
  775.                                           no menu bar
  776.                   errAENoUserInteraction
  777.                                   -1713   The application is
  778.                                           refusing to interact
  779.                                           with other processes
  780.                                           or (if Menu Events
  781.                                           extension is locked)
  782.                                           with remote processes
  783.                   noSuchMenuErr   -15950  The application has
  784.                                           no such menu
  785.                   noSuchMenuItemErr
  786.                                   -15951  The menu has no
  787.                                           such item
  788.                   menuItemDisabledErr
  789.                                   -15952  The item is
  790.                                           disabled
  791.                   menuEventPendingErr
  792.                                   -15953  Another Menu event
  793.                                           is already pending
  794.                                           on this application
  795.                   menuMismatchErr
  796.                                   -15955  The given menu ID
  797.                                           and menu title
  798.                                           do not match
  799.                   menuItemMismatchErr
  800.                                   -15956  The given menu item ID
  801.                                           and menu item text
  802.                                           do not match
  803.  
  804.  
  805. Constants defined in the Menu Events suite
  806.  
  807. Constant               Value
  808.  
  809. kAEMEQueryMenu         'qmn '
  810. kAEMEQueryMenuList     'qmn#'
  811. kAEMESelectMenuItem    'semi'
  812. keyCommandKeyPressed   'comk'
  813. keyControlKeyPressed   'conk'
  814. keyMenuEnabled         'mnen'
  815. keyMenuEventsTattoo    'Mセnu'
  816. keyMenuID              'mnid'
  817. keyMenuItemCmd         'micm'
  818. keyMenuItemEnabled     'mien'
  819. keyMenuItemIcon        'miic'
  820. keyMenuItemID          'miid'
  821. keyMenuItemMark        'mima'
  822. keyMenuItemStyle       'mist'
  823. keyMenuItemText        'mite'
  824. keyMenuMDEFID          'mndf'
  825. keyMenuTitle           'mnti'
  826. keyOptionKeyPressed    'optk'
  827. keyShiftKeyPressed     'shik'
  828. kMEEventClass          'Mセnu'
  829. menuEventPendingErr    -15953
  830. menuItemDisabledErr    -15952
  831. menuItemMismatchErr    -15956
  832. menuMismatchErr        -15955
  833. noSuchMenuErr          -15950
  834. noSuchMenuItemErr      -15951
  835.  
  836.  
  837.  
  838. Limitations
  839.  
  840.  
  841. Some applications refuse to submit to the trickery of Menu Events.  The
  842. prime example is any version of Finder which predates the Power
  843. Macintosh (version 7.1.2).  It is not truly an Apple event server, and it
  844. only respects events of known types.  Any other high-level event is not
  845. replied to, and the send will time out.  ResEdit 2.1.1 is similar.  Some
  846. Microsoft applications handle Apple events in a non-standard fashion,
  847. binding their own event handlers over all Apple event classes, and
  848. therefore should not be targeted.
  849.  
  850. The only way to know for sure is to try the ones you are interested in
  851. controlling.  Certainly, anything you write yourself is a candidate, as long
  852. as you follow the practices suggested in Apple documentation, namely:  Be
  853. high-level-event-aware.  Always be ready to accept and dispatch an
  854. Apple event.  Assume that any high-level event you donユt recognize is an
  855. Apple event, and dispatch it as such.  If an unknown event reaches your
  856. wildcard event handler, return errAEEventNotHandled, so that system
  857. event handlers can get a crack at it.  Donユt deny other programs on the
  858. same machine the right to request user interaction, which is the default.
  859.  
  860. Another limitation you should know about is that Menu Events canユt
  861. operate dialogs and alerts which the target application may post in
  862. response to the menu action.  If the menu item text ends in an ellipsis
  863. ('ノ') character, you can bet that the application will post a dialog or alert
  864. box.  It is then up to the local user to operate the controls.
  865.  
  866. If the target machine is under the influence of a screen saver or security
  867. package which would present a modal dialog in response to a mouse click,
  868. then Query Menu and Select Menu Item events will time out.  The same is
  869. true if the target machine is already showing a modal dialog, preventing
  870. Menu Events from activating the target application.
  871.  
  872. A known conflict exists between Menu Events and Help on Wheels.  If you
  873. send a Menu event to an application which does a casual help display
  874. before performing the menu action, and if the help server is running,
  875. problems may occur with the application.  The problem is that the Menu
  876. eventユs user interaction ends when the receiving application sends an
  877. Apple event to the help server, causing it to return to the background.  If
  878. the menu action causes a call to the Standard File Manager or any other
  879. code which should not be called when in the background, the application
  880. may hang.
  881.  
  882.  
  883.  
  884. Programmer Notes
  885.  
  886.  
  887. Write to the author at the above address if you want to know more about
  888. the Menu Events extension or how it was programmed.
  889.  
  890.  
  891.  
  892. Acknowledgements
  893.  
  894.  
  895. Thanks to C.K. Haun and the other folks at Apple Developer Technical
  896. Support who put together those clever little code snippets which give
  897. folks like me such odd ideas.
  898.  
  899. Special thanks to the many fine people who beta-tested this software,
  900. including Ken Linger, Chris Reynolds, Michele Marques, Chris Kaltwasser,
  901. James Edward Davis, and Leonard Rosenthol, and to Fred Terry for his
  902. hospitality at the MacScripting mailing list.
  903.  
  904.  
  905.  
  906. Revision History
  907.  
  908.  
  909. 1.3 (March 6, 1996)
  910. ・  Public AWOL Utilities 1.3 release.
  911. ・  Allowed menus and menu items to be specified using string parameters,
  912. with or without the corresponding numeric ID parameters.  An error is
  913. returned if the numeric and string parameters do not match.
  914. ・  Added support for modifier keys (Shift, Control, Option, Command) in
  915. the Query Menu event.
  916. ・  Improved application compatibility by simulating a menu bar click, to
  917. force the application to update its menus, before reading the contents of a
  918. menu in response to a Query Menu or Select Menu Item event.
  919. ・  Changed the response to a menu selection with the Caps Lock key down
  920. to a simple Apple event recording action, instead of having the target
  921. application send itself a Menu event to invite recording.
  922. ・  Added an error string parameter to the reply event when an error
  923. occurs.
  924. ・  Moved the error codes from the -21000 range to the -15950 range, so
  925. that errors are reported sensibly in AppleScript alerts.
  926. ・  Rewrote メMenu Events Sample Scriptモ to make use of the new optional
  927. string parameters.
  928.  
  929. 1.2 (October 17, 1994)
  930. ・  Public AWOL Utilities 1.2 release.
  931. ・  No revisions.
  932.  
  933. 1.1.2 (April 19, 1994)
  934. ・  Added support for script recording by forcing high-level-event-aware
  935. applications to send themselves Menu events when the user selects a
  936. menu item and the Caps Lock key is down.
  937. ・  Added support for modifier keys (Shift, Control, Option, Command) in
  938. the Select Menu Item event.
  939. ・  Removed the nonStandardMenuErr (-21004) code in favor of the new
  940. keyMenuMDEFID parameter in the reply to the Query Menu List event, to
  941. improve compatibility with target applications which use slightly
  942. non-standard menu definition procedures.
  943.  
  944. 1.1.1 (April 11, 1994)
  945. ・  Added メMenu Events Scripting Additionモ and メMenu Events Sample
  946. Scriptモ in place of メMenu Events 'aete'モ resource file.
  947.  
  948. 1.1 (March 28, 1994)
  949. ・  Public AWOL Utilities 1.1 release.
  950. ・  Documented that Menu Events works with Finder 7.1.2.
  951.  
  952. 1.0.7 (March 13, 1994)
  953. ・  Menu Events Help presents a useful message if the user tries to open or
  954. print it when the help server is absent.
  955.  
  956. 1.0.6 (February 27, 1994)
  957. ・  Added protection against loading duplicate copies of the extension.
  958.  
  959. 1.0.5 (February 6, 1994)
  960. ・  Improved compatibility with At Ease and other applications which flush
  961. mouse-down events when they become active.
  962.  
  963. 1.0.4 (January 30, 1994)
  964. ・  If the Shift key is pressed on startup, the extension will not be loaded.
  965. If the Help or Command-? key is pressed, the extension will delay up to
  966. one second to let the user release the key(s).
  967.  
  968. 1.0.3 (January 19, 1994)
  969. ・  Added メMenu Events 'aete'モ resource file.
  970.  
  971. 1.0.2 (January 11, 1994)
  972. ・  Fixed bug which sent the target application into a notification wait state
  973. if it received a Menu event from a remote sender.
  974.  
  975. 1.0.1 (December 31, 1993)
  976. ・  Initial AWOL Utilities 1.0.1 release.
  977.